<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>传参，改变div属性</title>
	<style>
       #A{
       	width: 150px;
       	height: 200px;
       	background-color: gray;
       	color: yellow;
       	font-weight: 900;
       	font-size: 16px;
       }
	</style>
</head>
<body>
    <center>
		<label for="">属性名</label><input type="text" value="background">
		<label for="">属性值</label><input type="text" value="gray">
        <P>
        <button>确定</button>
        <button>重置</button>
        </P>
		<div id="A">在上方边框里输入‘属性名’‘属性值’，点击确定按钮查看效果</div>
	</center>	
</body>
</html>
<script>

	var changeStyle = function (elem,name,value) {
		elem.style[name] = value
	}
    var node=document.getElementsByTagName('button');
    var node1=document.getElementsByTagName("input");
    var code= document.getElementById("A");

     node[0].onclick = function(){
     	
            changeStyle(code,node1[0].value,node1[1].value)
         } 
     node[1].onclick = function(){
    	code.style.cssText = ''
    }   
</script>